#include <iostream>

// 涨薪请求
struct request
{
    int money;
};

// 抽象上级
class Manager
{
public:
    Manager(const std::string &name):name(name) {}
    void SetManager(Manager *m) // 设置你的上级
    {
        this->m = m;
    }
    virtual void GetRequest(request *r) = 0;
protected:
    std::string name;
    Manager *m; // 直接上级的指针
};

// 普通经理
class CommonManager : public Manager
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money <= 500)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求" << std::endl;
        }
        else
        {
            m->GetRequest(r);
        }
    }
};

// 总监
class Major : public Manager
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money <= 1000)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求" << std::endl;
        }
    }
};

// 总经理
class GeneralManager : public Manager
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money > 1000)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求" << std::endl;
        }
    }
};

int main()
{
    Manager *m1 = new CommonManager("张经理");
    Manager *m2 = new Major("李总监");
    Manager *m3 = new GeneralManager("王总");

    // 形成责任链
    m1->SetManager(m2);
    m2->SetManager(m3);

    request *r = new request;
    r->money = 1500;
    m1->GetRequest(r); // 把请求给普通经理

    return 0;
}